libxl: correct error path in libxl_userdata_retrieve
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 28 Jan 2011 16:43:53 +0000 (16:43 +0000)
committerIan Jackson <ian.jackson@eu.citrix.com>
Fri, 28 Jan 2011 16:43:53 +0000 (16:43 +0000)
Firstly, if libxl_read_file_contents fails, it doesn't really leave
*data and *datalen_r undefined - it leaves them unchanged.  Tighten up
the spec for the benefit of libxl_userdata_retrieve.

Secondly, libxl_userdata_retrieve ignored errors, assuming they were
all ENOENT.  Instead it should fail on unexpected errors.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Jim Fehlig <jfehlig@novell.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_dom.c
tools/libxl/libxl_utils.h

index 7e49c5afaf9a90bf79346a2c995ec283f2c3abf6..29a92fd172d34a623c151aed9a836c5f6a4e62f7 100644 (file)
@@ -671,7 +671,10 @@ int libxl_userdata_retrieve(libxl_ctx *ctx, uint32_t domid,
     }
 
     e = libxl_read_file_contents(ctx, filename, data_r ? &data : 0, &datalen);
-
+    if (e && errno != ENOENT) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
     if (!e && !datalen) {
         LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "userdata file %s is empty", filename);
         if (data_r) assert(!*data_r);
index 3ec67e5eb07f6e1e6499c07265f1cacb8329e044..348dd79864b499db299db121347ccc3af07d2fc9 100644 (file)
@@ -36,7 +36,7 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
   /* Reads the contents of the plain file filename into a mallocd
    * buffer.  Returns 0 or errno.  Any errors other than ENOENT are logged.
    * If the file is empty, *data_r and *datalen_r are set to 0.
-   * On error, *data_r and *datalen_r are undefined.
+   * On error, *data_r and *datalen_r are unchanged.
    * data_r and/or datalen_r may be 0.
    */